package org.dream.ui;

import java.awt.BorderLayout;
import java.util.Vector;

import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;

import org.dream.domain.Dealrecord;
import org.dream.persistence.PersistenceServiceImpl;

/**
 * 止损交易测试
 * 
 * @author 关攀攀
 */
public class DealRecordMoneyFlowPanel extends JPanel {
	private JComboBox box;
	private JTable table;
	private Vector<String> columnNames = new Vector<String>();
	private Vector<Vector<Object>> data = new Vector<Vector<Object>>();

	public DealRecordMoneyFlowPanel() {
		super(new BorderLayout());
		// 添加股票分类Box
		box = new JComboBox();
		box.addItem("盈亏计算");
		this.add(box, BorderLayout.NORTH);

		// 初始化股票数据表格
		addStockDataTable();

	}

	/**
	 * 初始化股票数据表格
	 */
	private void addStockDataTable() {
		columnNames.add("发生日期");
		columnNames.add("成交时间");
		columnNames.add("业务名称");
		columnNames.add("发生金额");
		columnNames.add("资金总投入");
		columnNames.add("交易组");
		double totalMoney=0.0;
		for (Dealrecord dealRecord : new PersistenceServiceImpl().findMoneyFlowList()) {
			Vector<Object> row = new Vector<Object>();
			row.add(dealRecord.getHappenDate());
			row.add(dealRecord.getHappenTime());
			row.add(dealRecord.getBusinessName());
			row.add(dealRecord.getHappenCharge());
			totalMoney+=dealRecord.getHappenCharge();
			row.add(totalMoney);
			row.add("可编辑");
			data.add(row);
		}

		table = new JTable(data, columnNames) {
			@Override
			public void tableChanged(TableModelEvent e) {

				super.tableChanged(e);
			}
		};
		table.setEditingColumn(5);
		add(new JScrollPane(table), BorderLayout.CENTER);
	}

	/**
	 * 更新数据表格数据
	 */
	/*
	 * private void refreshStockDataTable() { data =
	 * zhiZunService.getTableStock((StockKind) box.getSelectedItem(), null,
	 * null); tableModel = new DefaultTableModel(data, columnNames);
	 * table.setModel(tableModel); table.updateUI(); }
	 */
}
